package com.lagou.controller;

import com.lagou.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/position")
public class PositionController {

    @Autowired
    private PositionService positionService;

    @GetMapping({"/index","/"})
    public String indexPage(){
        return "index";
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String,Object>> searchPosition(@PathVariable("keyword") String keyword,@PathVariable("pageNo") int pageNo,@PathVariable("pageSize") int pageSize) throws Exception{
        List<Map<String, Object>> list = positionService.searchPos(keyword, pageNo, pageSize);
        return list;

    }

    @RequestMapping("/importall")
    public String importAll(){
        try {
            positionService.importAll();;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }

}
